package pkg;

public class Demo4 {
	public static void main(String[] args) {
		Computer p1 = new Computer();
		p1.add(new Mouse());
		p1.add(new KeyBoard());
		p1.add(new Micro());
		p1.powerOn();
		System.out.println();
		p1.powerOff();
	}
}

class Computer {
	private USB[] arr = new USB[10];
	public void add(USB usb) {
		for(int i = 0; i < arr.length; i++) {
			if(arr[i] == null) {
				arr[i] = usb;//传入
				break;
			}
		}
	}
	public void powerOn() {
		for(int i = 0; i < arr.length; i++) {
			if(arr[i] != null) {
				arr[i].turnOn();//打开
			}
		}
		System.out.println("Boot success!");
	}
	
	public void powerOff() {
		for(int i = 0; i < arr.length; i++) {
			if(arr[i] != null) {
				arr[i].turnOff();//关闭
			}
		}
		System.out.println("LogOut success!");
	}
}

interface USB {
	abstract void turnOn();
	abstract void turnOff();
}

class Mouse implements USB{
	@Override
	public void turnOn() {
		System.out.println("mouse is on.");
	}

	@Override
	public void turnOff() {
		System.out.println("mouse is off.");
	}
}

class KeyBoard implements USB{
	@Override
	public void turnOn() {
		System.out.println("KeyBoard is on.");
	}

	@Override
	public void turnOff() {
		System.out.println("KeyBoard is off.");
	}
}

class Micro implements USB{
	@Override
	public void turnOn() {
		System.out.println("Micro is on.");
	}

	@Override
	public void turnOff() {
		System.out.println("Micro is off.");
	}
}